package edu.hunau.cxb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.Writer;

/**
 * @author hb
 * @create 2020-03-27 11:43
 */
@Controller
public class RequestParamTestController {

    @RequestMapping("/testRequestParam")
    public String testRequestParam(
            @RequestParam("name") String username,
            @RequestParam(value="age",required = false,defaultValue = "0" )int age){

        System.out.println("username=" + username + " ,age=" + age);
        return "success";
    }


    @RequestMapping("/testServletApi")
    public String testServletApi(HttpServletRequest request, HttpServletResponse response, Writer out, HttpSession session){
        System.out.println(request);
        System.out.println(response);
        System.out.println(out);
        System.out.println(session);

        return "success";
    }


    @RequestMapping("/testRequestHeader")
    public String  testRequestHeader(@RequestHeader("Accept-Encoding") String encoding,@RequestHeader("Accept-Language") String language){
        System.out.println(encoding);
        return "success";
    }

    @RequestMapping("/testCookieValue")
    public String testCookieValue(@CookieValue(value="JSESSIONID",required = false) String sessionId){
        System.out.println(sessionId);
        return "success";
    }
}
